package org.xml.xpath4js.client;

/* 
xpath4js is a GWT implementation of XPath 2.0 
Copyright (C) 2010  Peter Schonefeld (peter dot schonefeld at gmail)

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

import java.util.Iterator;
import java.util.Vector;

@SuppressWarnings("unchecked")
public class ExprTreeNode {
	
	public boolean IsExprStart = false;
	public boolean IsRoot = false;
	/**
     * @gwt.typeArgs <com.artbase.xpath.client.ExprTreeNode>
     */		
	public Vector Children = new Vector(); //GWT Compile
	/**
     * @gwt.typeArgs <com.artbase.xpath.client.ExprTreeNode>
     */		
	public Vector Siblings = new Vector(); //GWT Compile
	public XPathSyntaxNodeKind Kind = XPathSyntaxNodeKind.ETNK_STEP; //GWT compile
	public XPathTokenEntry Token = new XPathTokenEntry();//GWT compile
    
	public ExprTreeNode(){
		this.Token = new XPathTokenEntry(); //GWT Compile
		this.IsExprStart = false;
		this.IsRoot = false;		
	};

	//public ExprTreeNode(XPathSyntaxNodeKind kind){};
	
	public XPathTokenName GetAxisName(){
		if(this.Kind == XPathSyntaxNodeKind.ETNK_FORWARD_AXIS || this.Kind == XPathSyntaxNodeKind.ETNK_REVERSE_AXIS) {
			return this.Token.Token.Token.Name;
		}
		else return null;	
	};
	
	public void Traverse(){};
	
	public void Visit(){
		switch(this.Kind){
		case ETNK_STEP: 
			if(this.IsExprStart){
				;
			}
		}	
	};
	
	public String TestTraverse(){
		String result = "";
		TestVisit();
		/**
	     * @gwt.typeArgs <com.artbase.xpath.client.ExprTreeNode>
	     */			
		Iterator it = (Iterator) this.Siblings.iterator();
		while(it.hasNext()){
			ExprTreeNode i = (ExprTreeNode)it.next();
			result += " sibling:  ";
			result += ((ExprTreeNode)i).TestTraverse();
		}
		
		it = (Iterator) this.Children.iterator();
			while(it.hasNext()){
		    ExprTreeNode i = (ExprTreeNode)it.next();		
			result += " child:  ";
			result += ((ExprTreeNode)i).TestTraverse();
		}
		return result += "\n";		
	};
	
	public String TestVisit(){
		return " Kind: " + this.Kind;
	};
}
